package com.cy.study.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cy.study.common.BasePageReq;
import com.cy.study.common.Response;
import com.cy.study.req.PlanAddReq;
import com.cy.study.req.PlanDeleteReq;
import com.cy.study.req.PlanUpdateReq;
import com.cy.study.res.PlanListRes;
import com.cy.study.service.UserPlanService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 用户计划控制器
 */
@RequiredArgsConstructor
@RequestMapping("/userPlan")
@RestController
@CrossOrigin
@Slf4j
public class UserPlanController {

    private final UserPlanService userPlanService;

    /**
     * 用户端添加计划
     * @param req
     * @return
     */
    @PostMapping("/addPlan")
    public Response<Integer> addPlan(@RequestBody PlanAddReq req){
        Integer id = userPlanService.addPlan(req);
        return Response.success(id);
    }


    /**
     * 用户端删除计划
     * @param req
     * @return
     */
    @PostMapping("/deletePlan")
    public Response deletePlan(@RequestBody PlanDeleteReq req){
        userPlanService.deletePlan(req);
        return Response.success();
    }

    /**
     * 用户端更新计划
     * @param req
     * @return
     */
    @PostMapping("/updatePlan")
    public Response updatePlan(@RequestBody PlanUpdateReq req){
        userPlanService.updatePlan(req);
        return Response.success();
    }

    /**
     * 用户端计划列表
     * @param req
     * @return
     */
    @PostMapping("/planList")
    public Response<Page<PlanListRes>> planList(@RequestBody BasePageReq req){
        Page<PlanListRes> res = userPlanService.planList(req);
        return Response.success(res);
    }

}
